<?php
// application/api/validate/RoleValidate.php

namespace app\api\validate;

use think\Validate;

class RoleValidate extends Validate
{
    protected $rule = [
        'role_name' => 'require|max:50',
        'role_key'  => 'require|max:100',
        'role_sort' => 'number',
        'status'    => 'require|in:0,1',
    ];

    protected $message = [
        'role_name.require' => '角色名称不能为空',
        'role_name.max'     => '角色名称不能超过50个字符',
        'role_key.require'  => '角色标识不能为空',
        'role_key.max'      => '角色标识不能超过100个字符',
        'role_sort.number'  => '排序必须是数字',
        'status.require'    => '状态不能为空',
        'status.in'         => '状态值不正确',
    ];

    // 添加场景
    protected $scene = [
        'add'  => ['role_name', 'role_key', 'role_sort', 'status'],
        'edit' => ['role_name', 'role_key' => 'require|max:100,role_key^id', 'role_sort', 'status'],
    ];
}